package com.wu.service.weixin.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wu.common.constant.Constant;
import com.wu.common.page.PageResult;
import com.wu.common.service.impl.BaseServiceImpl;
import com.wu.dao.weixin.dao.WeixinHuoDongMapper;
import com.wu.dao.weixin.vo.WxActGoldeneggsVo;
import com.wu.entity.sys.SysDictDataEntity;
import com.wu.entity.weixin.po.WxActGoldeneggs;
import com.wu.service.sys.query.SysDictDataQuery;
import com.wu.service.sys.query.WeixinHuoDongQuery;
import com.wu.service.weixin.service.WxHuoDongService;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 用户管理
 *
 * @author wzd
 */
@Service
@AllArgsConstructor
public class WxHuoDongServiceImpl extends BaseServiceImpl<WeixinHuoDongMapper, WxActGoldeneggs> implements WxHuoDongService {

    @Override
    public PageResult<WxActGoldeneggsVo> page(WeixinHuoDongQuery query) {
        // 查询参数
        Map<String, Object> params = getParams(query);
        // 分页查询
        IPage<WxActGoldeneggs> page = getPage(query);
        params.put(Constant.PAGE, page);
        // 数据列表
        List<WxActGoldeneggsVo> list = baseMapper.getList(params);
        return new PageResult<WxActGoldeneggsVo>(list, page.getTotal());
    }

    @Override
    public void deleteByIds(List<String> idList) {
        baseMapper.deleteByIds(idList);
    }

    @Override
    public void save(WxActGoldeneggsVo vo) {
        WxActGoldeneggs entity  = new WxActGoldeneggs();
        BeanUtils.copyProperties(vo,entity);
        baseMapper.insert(entity);
    }

    @Override
    public void release(List<Long> idList) {
        //循环发布，只针对待发布状态的数据
        idList.forEach(item->{
            WxActGoldeneggs entity = baseMapper.selectOne(getWrapper(item));
            if(entity.getStatus().equals(0)){

            }
        });
    }


    private Map<String, Object> getParams(WeixinHuoDongQuery query){
        Map<String, Object> params = new HashMap<>();
        params.put("title", query.getTitle());
        params.put("status", query.getStatus());
        // 数据权限
        params.put(Constant.DATA_SCOPE, getDataScope("t1", null));

        return params;
    }



    private Wrapper<WxActGoldeneggs> getWrapper(Long id){
        LambdaQueryWrapper<WxActGoldeneggs> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(WxActGoldeneggs::getId, id);
        return wrapper;
    }
}
